package com.huaxin.device.dto.enums.validator;

import com.huaxin.device.dto.enums.DeviceStatus;
import com.huaxin.device.dto.enums.validation.ValidDeviceStatus;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class DeviceStatusValidator implements ConstraintValidator<ValidDeviceStatus, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 允许 null 或空值通过（如果字段本身允许 null）
        if (value == null || value.trim().isEmpty()) {
            return true;
        }
        return DeviceStatus.isValid(value);
    }
}